package dev.android.yeqh.tvannounce.adapters;

import java.util.ArrayList;
import java.util.List;
import dev.android.yeqh.tvannounce.model.Program;
import dev.android.yeqh.tvannounce.R;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ProgramAdapter extends BaseAdapter{
	List<Program> programList = null;
	Context context = null;
	int layoutId;
	
	public ProgramAdapter(List<Program> programList, Context context, int layoutId) {
		if (programList == null) {
			this.programList = new ArrayList<Program>();
		} else {
			this.programList = programList;
		}
		this.context = context;
		this.layoutId = layoutId;
	}
	
	public void setPrograms(List<Program> programList) {
		if (programList == null) {
			this.programList = new ArrayList<Program>();
		} else {
			this.programList = programList;
		}
	}

	public int getCount() {
		return programList.size();
	}

	public Object getItem(int position) {
		return programList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;
		TextView programTime = null;
		TextView programName = null;
		
		view = ((Activity)context).getLayoutInflater().inflate(layoutId, null);
		programTime = (TextView)view.findViewById(R.id.item_program_time);
		programName = (TextView)view.findViewById(R.id.item_program_name);
		
		programTime.setText(programList.get(position).getProgramTime());
		programName.setText(programList.get(position).getProgramName());
		
		return view;
	}

}
